package com.pureut.production.controller;

import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.dto.OperationInformationDto;
import com.pureut.production.service.OperationInformationService;
import com.pureut.production.domain.vo.OperationInformationVo;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: YSL
 * @Date: 2023/2/6 15:13
 * @Desc: 工序信息
 */
@RestController
@RequestMapping("/operationInformation")
public class OperationInformationController extends BaseController {

    /**
     * 工序信息service
     */
    @Autowired
    OperationInformationService operationInformationService;

    /**
     * 查看单据列表
     */
    @RequiresPermissions("productionTube:processmage:processinfo:list")
    @GetMapping("/list")
    public TableDataInfo selectOperationList(OperationInformationVo pickingPurchaseVo) {
        startPage();
        // 查询工序信息列表
        List<OperationInformationDto> operationInformationDtos = operationInformationService.selectOperationList(pickingPurchaseVo);
        return getDataTable(operationInformationDtos);
    }

    /**
     * 查看单据
     */
    @RequiresPermissions("productionTube:processmage:processinfo:query")
    @GetMapping("/operationById/{id}")
    public AjaxResult view(@PathVariable("id") Long id) throws Exception {
        return AjaxResult.success(operationInformationService.selectOperationByIds(id));
    }

    /**
     * 新增工序信息
     */
    @RequiresPermissions("productionTube:processmage:processinfo:add")
    @Log(title = "新增工序信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody OperationInformationVo operationInformationVo) throws Exception {
        return toAjax(operationInformationService.save(operationInformationVo));
    }

    /**
     * 修改工序信息
     */
    @RequiresPermissions("productionTube:processmage:processinfo:edit")
    @Log(title = "修改工序信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody OperationInformationVo operationInformationVo) throws Exception {
        return toAjax(operationInformationService.edit(operationInformationVo));
    }

    /**
     * 删除工序信息
     */
    @RequiresPermissions("productionTube:processmage:processinfo:remove")
    @Log(title = "工序信息删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{idStr}")
    public AjaxResult delete(@PathVariable("idStr") String idStr) {
        return toAjax(operationInformationService.deleteOperationInformationById(idStr));
    }


}
